//
//  OpinionDetailViewController.m
//  安好
//
//  Created by 冯凯 on 14-11-25.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "OpinionDetailViewController.h"

@interface OpinionDetailViewController ()

@end

@implementation OpinionDetailViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = [ClassMethodsViewController colorWithHexString:@"#f2f2f2"];
    
    [self makeNavBar];

    [self viewWithTextView];
}
#pragma mark - 配置导航条
-(void)makeNavBar
{
    self.navigationItem.title = self.opinionString;
    // 返回按钮图片
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backMoreVC)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem= backBtnImg;
    // 完成
    UIBarButtonItem *OkBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_完成.png"] style:UIBarButtonItemStylePlain target:self action:@selector(finish)];
    OkBtnImg.tintColor = [UIColor whiteColor];
    OkBtnImg.tag = 100;
    self.navigationItem.rightBarButtonItem = OkBtnImg;
    
}
- (void)backMoreVC
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)finish
{
    if (self.isLoad == NO) {
        self.isLoad = YES;
        [self loadWithData];
    }
}
- (void)viewWithTextView
{
    self.opinionTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 10, kScreenWidth, kScreenHeight - iOS7TopMargin - 209 - 25)];
    [self.view addSubview:self.opinionTextView];
    [self.opinionTextView becomeFirstResponder];
    
}
- (void)loadWithData
{
    //postUrl
    NSString *postURL = [NSString stringWithFormat:@"%@user/newfeedback/",kBaseURL];
    //post参数列表
    NSString * catgoryid = nil;
    if ([self.opinionString isEqualToString:@"提交意见"]){
    catgoryid = @"0";
    }else if ([self.opinionString isEqualToString:@"登录缓慢"]){
        catgoryid = @"2";
    }else if ([self.opinionString isEqualToString:@"部分功能无法使用"]){
        catgoryid = @"3";
    }else if ([self.opinionString isEqualToString:@"运行不够流畅"]){
        catgoryid = @"4";
    }else if ([self.opinionString isEqualToString:@"感觉很耗电"]){
        catgoryid = @"5";
    }else if ([self.opinionString isEqualToString:@"感觉很耗流量"]){
        catgoryid = @"6";
    }
//    NSLog(@"saas  %@",self.opinionTextView.text);
    NSDictionary *parameters = @{@"platform": kPlatform,@"version":kVersion,@"type":@"1",@"catgoryid":catgoryid,@"additional":self.opinionTextView.text};
    //网络请求管理者
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    //开始请求
    [manager POST:postURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        MyNSLog("成功");
        NSNumber * statusNum = [responseObject objectForKey:@"status"];
        //用NSNumberFormatter把 NSNumber类型的数字-->转成字符串
        NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
        NSString * statusString = [numberFormatter stringFromNumber:statusNum];//得到字符串对象: "0" / "1"
//        NSLog(@"saad  dddd   %@",responseObject);
        self.isLoad = NO;
        if ([statusString isEqualToString:@"0"]) {
//            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示"
//                                                            message:[responseObject objectForKey:@"msg"]
//                                                           delegate:self
//                                                  cancelButtonTitle:@"确定"
//                                                  otherButtonTitles:nil,nil];
//            alert.tag = 100;
//            [alert show];
            [self showCustomHudSingleLine:[responseObject objectForKey:@"msg"]];

        }else{
            
            [self showCustomHudSingleLine:@"您的意见已成功提交，感谢你对安好的关注"];
            [self performSelector:@selector(popView) withObject:nil afterDelay:1.5f];
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        self.isLoad = NO;

        MyNSLog("失败");
    }];
}
- (void)popView
{
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
    if (alertView.tag == 101) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
